import request from "@/utils/request.ts";
import {ResRoleType, Role} from "@/api/acl/role/type.ts";
import {ResMenuType} from "@/api/acl/user/type.ts";

export const reqGetAllRole = (page: number, limit: number, roleName: string) => request.get<any, ResRoleType>(`/admin/acl/role/${page}/${limit}?roleName=${roleName}`)
export const reqAddOrUpdateRole = (data: Role) => {
    if (!data.id)
        return request.post('/admin/acl/role/save', data);
    else
        return request.post('/admin/acl/role/update', data);
};
export const reqGetAllPermission = (id: number) => request.get<any, ResMenuType>(`/admin/acl/permission/toAssign/${id}`)

export const reqSetPermission = (roleId: number, permissionId: number[]) => request.post(`/admin/acl/permission/doAssign?roleId=${roleId}&permissionId=${permissionId}`)

export const reqDelRole = (id:number) => request.delete(`/admin/acl/role/remove/${id}`)